package com.Ajava1704.forIO;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 作者: LCG
 * 日期: 2020/2/17 10:47
 * 描述:
 */
public class ForRunableServer implements Runnable {

    private ServerSocket serverSocket;

    public ForRunableServer(ServerSocket serverSocket) {
        this.serverSocket = serverSocket;
    }

    @Override
    public void run() {

        try{
            while (true){
                Socket accept = serverSocket.accept();
                InputStreamReader inputStreamReader=new InputStreamReader(accept.getInputStream());
                BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
                String readLine = bufferedReader.readLine();
                System.out.println("=====>"+readLine);

                Thread.sleep(3000);

                PrintWriter printWriter=new PrintWriter(accept.getOutputStream());
                printWriter.println("---server data---");

                printWriter.flush();

            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
